﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using DotVVM.Framework.Hosting;
using Microsoft.AspNetCore.Http;

namespace VOICeVIO.Hybrid
{
    public enum Singer
    {
        None,
        Yoko,
        Yokun,
        TsudumiCool,
        TsudumiBashful,
        IA,
    }

    public static class Helper
    {
        public static bool IsASCII(this string value)
        {
            // ASCII encoding replaces non-ascii with question marks, so we use UTF8 to see if multi-byte sequences are there
            return Encoding.UTF8.GetByteCount(value) == value.Length;
        }

        public static string GetClientIP(this HttpContext context)
        {
            return context?.Connection.RemoteIpAddress.ToString() ?? "";
        }

        public static string GetMd5(Stream stream)
        {
            var hash = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(stream);

            string hashStr = BitConverter.ToString(hash).Replace("-", "");

            return hashStr;
        }
    }
}
